package com;



import java.io.IOException;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CustomerInvoiceServlet
 */
@WebServlet("/CustomerInvoiceServlet")
public class CustomerInvoiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CustomerInvoiceServlet() {
        super();
    
    	// TODO Auto-generated constructor stub
    }
    

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
	
	try{ 
		String dt1="",nm1="",cd1="",in1="",amt1="",amtadj1="",balamt1="",cr1="";
		PrintWriter out = response.getWriter();
		String dt[]=request.getParameterValues("dte");
		String nm[]=request.getParameterValues("cname");
		String cd[]=request.getParameterValues("ccd");
		String cr[]=request.getParameterValues("cred");
		String in[]=request.getParameterValues("inn");
		//int count[]=Integer.parseInt(request.getParameterValues("cnt1"));
		String amt[]=request.getParameterValues("innamt");
	 String amtadj[]=request.getParameterValues("amtadjust");
	String balamt[]=request.getParameterValues("balamt");
		//System.out.println(count);
	int j=0;
		 Class.forName("com.mysql.jdbc.Driver");
		
	        Connection   con = DriverManager.getConnection("jdbc:mysql://localhost/BOA_Web", "root", "root");
	        Statement st=null;
	        String  query="";
	        int[] iNoRows=null;
	        st=con.createStatement();
        /// PreparedStatement ps=con.prepareStatement(query);
        // ps.setString(1, country);
	        for (int i=0;i<in.length;i++) {
	        	
	        cd1=cd[i];
	      String  query1="delete from salesinvoiceoutstanding where ccode = '"+cd1+"';";
	      st.executeUpdate(query1);
	        }
         for (int i=0;i<in.length;i++) {
        	 dt1=dt[i];
        	 nm1=nm[i];
        	 cd1=cd[i];
        	 cr1=cr[i];
        	 in1=in[i];
        	 amt1=amt[i];
        	 amtadj1=amtadj[i];
        	 balamt1=balamt[i];
        	 
        	 query="INSERT INTO salesinvoiceoutstanding(date,innum,svname,ccode,svamount,adjamount,balance,scred) VALUES('"+dt1+"','"+in1+"','"+nm1+"','"+cd1+"','"+amt1+"','"+amtadj1+"','"+balamt1+"','"+cr1+"')";
        	 j=st.executeUpdate(query);
        	 
        	}
         
        	con.close();
        	
        
     }catch(Exception e){
         e.printStackTrace();
     }
		 
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
